package o;

import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.LayoutInflater.Factory2;
import android.view.View;
import com.huawei.skinner.attrentry.SkinAttrFactory;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import o.fkp.e;

public class flt implements Factory2 {
    private static final String[] ˊ = new String[]{"color", "drawable", "style"};
    private static Field ˋ = fmt.ˊ(LayoutInflater.class, "mConstructorArgs");
    private static final String[] ˎ = new String[]{"android.widget.", "android.app.", "android.view.", "android.webkit."};
    private static final String[] ˏ = new String[]{"id", "layout_height", "layout_width", "text", "textSize"};
    private flp ॱ;

    public flt(flp o_flp) {
        this.ॱ = o_flp;
    }

    public View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        return onCreateView(str, context, attributeSet);
    }

    public View onCreateView(String str, Context context, AttributeSet attributeSet) {
        if (!attributeSet.getAttributeBooleanValue("http://schemas.android.com/apk/res-auto", "hwSkinEnable", false)) {
            return null;
        }
        View ॱ = ॱ(context, str, attributeSet);
        if (ॱ == null) {
            return null;
        }
        ˋ(context, attributeSet, ॱ);
        return ॱ;
    }

    private View ॱ(Context context, String str, AttributeSet attributeSet) {
        Object[] ॱ;
        Object obj;
        Exception e;
        Throwable th;
        Object obj2;
        Exception e2;
        View view;
        if (-1 == str.indexOf(".")) {
            String[] strArr = ˎ;
            int length = strArr.length;
            int i = 0;
            view = null;
            while (i < length) {
                String str2 = strArr[i];
                try {
                    LayoutInflater from = LayoutInflater.from(context);
                    ॱ = ॱ(from);
                    if (ॱ != null) {
                        try {
                            if (ॱ.length != 0) {
                                obj = ॱ[0];
                                try {
                                    ॱ[0] = context;
                                    view = from.createView(str, str2, attributeSet);
                                    if (view == null) {
                                        if (ॱ != null) {
                                            ॱ[0] = obj;
                                        }
                                        i++;
                                    } else if (ॱ == null) {
                                        return view;
                                    } else {
                                        ॱ[0] = obj;
                                        return view;
                                    }
                                } catch (Exception e3) {
                                    e = e3;
                                    try {
                                        fmq.ˎ("SkinnableViewFactory2.createView Error1 " + e.getMessage());
                                        if (ॱ == null) {
                                            ॱ[0] = obj;
                                        }
                                        i++;
                                    } catch (Throwable th2) {
                                        th = th2;
                                    }
                                }
                            }
                        } catch (Exception e4) {
                            e = e4;
                            obj = null;
                            fmq.ˎ("SkinnableViewFactory2.createView Error1 " + e.getMessage());
                            if (ॱ == null) {
                                ॱ[0] = obj;
                            }
                            i++;
                        } catch (Throwable th3) {
                            th = th3;
                            obj = null;
                        }
                    }
                    if (ॱ != null) {
                        ॱ[0] = null;
                    }
                    return null;
                } catch (Exception e5) {
                    e = e5;
                    obj = null;
                    ॱ = null;
                    fmq.ˎ("SkinnableViewFactory2.createView Error1 " + e.getMessage());
                    if (ॱ == null) {
                        ॱ[0] = obj;
                    }
                    i++;
                } catch (Throwable th4) {
                    th = th4;
                    obj = null;
                    ॱ = null;
                }
            }
            return view;
        }
        Object[] ॱ2;
        try {
            LayoutInflater from2 = LayoutInflater.from(context);
            ॱ2 = ॱ(from2);
            if (ॱ2 != null) {
                try {
                    if (ॱ2.length != 0) {
                        obj2 = ॱ2[0];
                        try {
                            ॱ2[0] = context;
                            view = from2.createView(str, null, attributeSet);
                            if (ॱ2 == null) {
                                return view;
                            }
                            ॱ2[0] = obj2;
                            return view;
                        } catch (Exception e6) {
                            e2 = e6;
                            try {
                                fmq.ˎ("SkinnableViewFactory2.createView Error2 " + e2.getMessage());
                                if (ॱ2 != null) {
                                    return null;
                                }
                                ॱ2[0] = obj2;
                                return null;
                            } catch (Throwable th5) {
                                th = th5;
                                if (ॱ2 != null) {
                                    ॱ2[0] = obj2;
                                }
                                throw th;
                            }
                        }
                    }
                } catch (Exception e7) {
                    e2 = e7;
                    obj2 = null;
                    fmq.ˎ("SkinnableViewFactory2.createView Error2 " + e2.getMessage());
                    if (ॱ2 != null) {
                        return null;
                    }
                    ॱ2[0] = obj2;
                    return null;
                } catch (Throwable th6) {
                    th = th6;
                    obj2 = null;
                    if (ॱ2 != null) {
                        ॱ2[0] = obj2;
                    }
                    throw th;
                }
            }
            if (ॱ2 != null) {
                ॱ2[0] = null;
            }
            return null;
        } catch (Exception e8) {
            e2 = e8;
            obj2 = null;
            ॱ2 = null;
            fmq.ˎ("SkinnableViewFactory2.createView Error2 " + e2.getMessage());
            if (ॱ2 != null) {
                return null;
            }
            ॱ2[0] = obj2;
            return null;
        } catch (Throwable th7) {
            th = th7;
            obj2 = null;
            ॱ2 = null;
            if (ॱ2 != null) {
                ॱ2[0] = obj2;
            }
            throw th;
        }
        if (ॱ != null) {
            ॱ[0] = obj;
        }
        throw th;
    }

    private Object[] ॱ(LayoutInflater layoutInflater) {
        Object[] objArr;
        if (ˋ == null) {
            ˋ = fmt.ˊ(LayoutInflater.class, "mConstructorArgs");
            if (ˋ == null) {
                fmq.ˎ("SkinnableViewFactory2.createView Error1: no field mConstructorArgs in LayoutInflater class founded!");
                return null;
            }
        }
        Object ॱ = fmt.ॱ(ˋ, layoutInflater);
        if (ॱ == null || !(ॱ instanceof Object[])) {
            fmq.ˎ("SkinnableViewFactory2.createView Error2: Value of field mConstructorArgs in LayoutInflater is null or type is not we need!");
            objArr = null;
        } else {
            objArr = (Object[]) ॱ;
        }
        return objArr;
    }

    private void ˋ(Context context, AttributeSet attributeSet, View view) {
        Collection arrayList = new ArrayList();
        for (int i = 0; i < attributeSet.getAttributeCount(); i++) {
            String attributeName = attributeSet.getAttributeName(i);
            String attributeValue = attributeSet.getAttributeValue(i);
            if ("hwThemeServiceEnable".equals(attributeName) && "true".equals(attributeValue)) {
                view.setTag(e.ˋ, "hwThemeServiceEnable");
            }
            if (attributeValue.startsWith("@") && ॱ(attributeName)) {
                try {
                    int indexOf;
                    String substring;
                    boolean z;
                    if (attributeValue.contains("/")) {
                        indexOf = attributeValue.indexOf("/");
                        substring = attributeValue.substring(indexOf + 1);
                        indexOf = context.getResources().getIdentifier(substring, attributeValue.substring(1, indexOf), context.getPackageName());
                        attributeValue = context.getResources().getResourceTypeName(indexOf);
                    } else {
                        indexOf = Integer.parseInt(attributeValue.substring(1));
                        substring = context.getResources().getResourceEntryName(indexOf);
                        attributeValue = context.getResources().getResourceTypeName(indexOf);
                    }
                    for (String equals : ˊ) {
                        if (equals.equals(attributeValue)) {
                            z = true;
                            break;
                        }
                    }
                    z = false;
                    if (z && SkinAttrFactory.isSupportedAttr(attributeName, view.getClass())) {
                        SkinAttr o_fko = SkinAttrFactory.get(attributeName, indexOf, substring, attributeValue, view.getClass());
                        if (o_fko != null) {
                            arrayList.add(o_fko);
                        }
                    }
                } catch (NumberFormatException e) {
                    fmq.ˎ("SkinnableViewFactory2.parseSkinableAttr Error1 " + e.getMessage());
                } catch (NotFoundException e2) {
                    fmq.ˎ("SkinnableViewFactory2.parseSkinableAttr Error2 " + e2.getMessage());
                }
            }
        }
        view.setTag(e.ˏ, "hwSkinEnable");
        if (!fmr.ˋ(arrayList)) {
            SkinnableView o_fkw = new SkinnableView();
            o_fkw.ˋ(view);
            o_fkw.ˏ().addAll(arrayList);
            o_fkw = this.ॱ.ˋ(o_fkw);
            if (flr.ˋ(context).ˋ()) {
                o_fkw.ˎ(true);
                if (flr.ˎ().ʻ() && flr.ˎ().ॱ() && view.getTag(e.ˋ) != null) {
                    o_fkw.ˊ();
                }
            }
        }
    }

    private boolean ॱ(String str) {
        for (String equals : ˏ) {
            if (equals.equals(str)) {
                return false;
            }
        }
        if (str.startsWith("layout_margin") || str.startsWith("padding")) {
            return false;
        }
        return true;
    }

    public void ˊ(Context context, View view, String str, int i) {
        if (view != null && SkinAttrFactory.isSupportedAttr(str, view.getClass())) {
            SkinAttr o_fko = SkinAttrFactory.get(str, i, context.getResources().getResourceEntryName(i), context.getResources().getResourceTypeName(i), view.getClass());
            if (o_fko != null) {
                SkinnableView o_fkw = new SkinnableView();
                o_fkw.ˋ(view);
                o_fkw.ˏ().add(o_fko);
                SkinnableView ˋ = this.ॱ.ˋ(o_fkw);
                ˋ.ˎ(true);
                if (flr.ˎ().ˋ() && flr.ˎ().ʻ() && flr.ˎ().ॱ() && view.getTag(e.ˋ) != null) {
                    ˋ.ˊ();
                }
            }
        }
    }
}
